<?php

namespace app\admin\model;

use think\Db;
use think\Model;

class GameChannelStats extends Model
{
    protected $connection = 'Db_stats';

    public function getInfo($map){
        $row = $this->where($map)->find();
        return $row;
    }

    public function edit($data){
        if(isset($data['id'])){
            $this->where('id',$data['id'])->update($data);
        }else{
            $this->insert($data);
        }
    }

    public function getLists($map){
        $all = $this
            ->where($map)
            ->field('sum(sum_amount) as sum_amount,sum(register_device) as register_device,sum(register_user) as register_user,sum(amount_user) as amount_user,sum(login_user) as login_user,sum(login_device) as login_device,sum(register_play) as register_play')
            ->find();
        $res = $this
            ->where($map)->select();
        foreach ($res as $k=>&$v){
            $v['channel_name'] = Db::name('channel')->where('id',$v['channel_id'])->value('name');
            $v['package_name'] = Db::name('package')->where('id',$v['package_id'])->value('package_name');
        }
        return ['all'=>$all,'list'=>$res];
    }
}
